﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace SERP.Modules.SalaryRules
{
    public partial class CalculationTypes : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
                BindCalculationTypes();
        }
        private string selectedVal = ""; 
        protected override void OnDataBinding(EventArgs e)
        {
            BindCalculationTypes();
            base.OnDataBinding(e);
        }
        private void BindCalculationTypes()
        {
            DataTable tbl = Controllers.SalaryRulesController.GetCalculationTypesTable();
            drd.DataTextField = "Name";
            drd.DataValueField = "ID";
            drd.DataSource = tbl;
            drd.DataBind();
            if (selectedVal != "")
            {
                ListItem ls = drd.Items.FindByValue(selectedVal);
                if (ls != null)
                    ls.Selected = true;
            }
        }
        public string SelectedValue
        {
            get { return drd.SelectedValue; }
            set
            {
                selectedVal = value;
                ListItem ls = drd.Items.FindByValue(value);
                if (ls != null)
                    ls.Selected = true;
            }
        }
    }
}